﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO.Packaging;
using System.IO;
using System.Xml.Linq;
using SmartSpace.Core;
using SmartSpace;
using SmartSapce.ServiceLocation;
using SmartSpace.Packaging;

namespace SmartSpace.WebApp._console.core
{
    public partial class module_list : System.Web.UI.Page
    {
        private Guid _selectedId;

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(Request.QueryString["id"]))
            {
                _selectedId = new Guid(Request.QueryString["id"]);
            }

            if (!IsPostBack)
            {
                ICoreService service = ServiceLocator.Get<ICoreService>();
                PagedList<Module> modules = service.GetModules(0, 999);
                if (modules.Count > 0 && _selectedId == default(Guid))
                {
                    _selectedId = modules[0].Id;
                }

                _ctlList.DataSource = modules;
                _ctlList.DataBind();

                foreach (var item in modules)
                {
                    if (item.Id == _selectedId)
                    {
                        _ctlListView.DataSource = item.Views;
                        _ctlListView.DataBind();
                        break;
                    }
                }
            }
        }

        public bool IsSelected(object moduleId)
        {
            if (_selectedId == (Guid)moduleId)
            {
                return true;
            }
            return false;
        }
    }
}